// import { createStore, combineReducers, applyMiddleware, compose } from 'redux'
import { createStore, applyMiddleware, compose } from 'redux'

import languageReducer from './language/languageReducer'
import recommendProductsReducer from './recommendProducts/recommendProductsReducer'
import thunk from 'redux-thunk'
import { actionLog } from './middlewares/actionLog'

//使用toolkit 导入combineReducers，不用在redux导入
import { productDetailSlice } from './productDetail/slice'
import { combineReducers, configureStore } from '@reduxjs/toolkit'

import { productSearchSlice } from './productSearch/slice'
import { userSlice } from './user/slice'
import { shoppingCartSlice } from './shoppingCart/slice'
import { placeOrderSlice } from './order/slice'

//利用combineReducers结合多个reducer
const rootReducer = combineReducers({
  language: languageReducer,
  recommendProducts: recommendProductsReducer,
  productDetail: productDetailSlice.reducer,
  productSearch: productSearchSlice.reducer,
  user: userSlice.reducer,
  shoppingCart: shoppingCartSlice.reducer,
  order: placeOrderSlice.reducer,
})

// const store = createStore(languageReducer)
//引入applyMiddleware thunk，创建中间件
// const store = createStore(
//   rootReducer,
//   compose(applyMiddleware(thunk, actionLog))
// )

//使用toolkit 重写store
const store = configureStore({
  reducer: rootReducer,
  middleware: (getDefaultMiddleware) => [...getDefaultMiddleware(), actionLog], //中间件
  devTools: true,
})

export type RootState = ReturnType<typeof store.getState>
export default store
